﻿using System;
using System.Collections.Generic;
using System.Text;
using Calculations.Calculations;
using System.Drawing;

namespace Atechnology.glassCAD.Shapes
{
    public class ComplexEllipse : IFigure
    {
        private PointF center;

        public PointF Center
        {
            get { return center; }
            set { center = value; }
        }

        private float a1;

        public float A1
        {
            get { return a1; }
            set { a1 = value; }
        }

        private float b1;

        public float B1
        {
            get { return b1; }
            set { b1 = value; }
        }

        private float a2;

        public float A2
        {
            get { return a2; }
            set { a2 = value; }
        }

        private float b2;

        public float B2
        {
            get { return b2; }
            set { b2 = value; }
        }

        private float a3;

        public float A3
        {
            get { return a3; }
            set { a3 = value; }
        }

        private float b3;

        public float B3
        {
            get { return b3; }
            set { b3 = value; }
        }

        private float a4;

        public float A4
        {
            get { return a4; }
            set { a4 = value; }
        }

        private float b4;

        public float B4
        {
            get { return b4; }
            set { b4 = value; }
        }

        public ComplexEllipse(PointF center, float a1, float b1, float a2, float b2, float a3, float b3, float a4, float b4)
        {
            this.center = center;
            this.a1 = a1;
            this.b1 = b1;
            this.a2 = a2;
            this.b2 = b2;
            this.a3 = a3;
            this.b3 = b3;
            this.a4 = a4;
            this.b4 = b4;
        }

        #region IFigure Members

        public System.Drawing.PointF GetOffsetPoint(float offset)
        {
            return this.GetAnglePoint((float)(2 * Math.PI * offset));
        }

        #endregion

        public System.Drawing.PointF GetAnglePoint(float angle)
        {
            float _angle = (float)(angle % (2 * Math.PI));
            PointF result = new PointF(0, 0);
            // Первый эллипс
            if (_angle >= 0 && _angle <= Math.PI / 2)
            {
                result = new PointF((float)(this.a1 * Math.Cos(_angle)), (float)(this.b1 * Math.Sin(_angle)));
            }
            // Второй эллипс
            else if (_angle > Math.PI / 2 && _angle <= Math.PI)
            {
                result = new PointF((float)(this.a2 * Math.Cos(_angle)), (float)(this.b2 * Math.Sin(_angle)));
            }
            // Третий эллипс
            else if (_angle > Math.PI && _angle <= 3 * Math.PI / 2)
            {
                result = new PointF((float)(this.a3 * Math.Cos(_angle)), (float)(this.b3 * Math.Sin(_angle)));
            }
            // Четвёртый эллипс
            else if (_angle > 3 * Math.PI / 2 && _angle <= 2 * Math.PI)
            {
                result = new PointF((float)(this.a4 * Math.Cos(_angle)), (float)(this.b4 * Math.Sin(_angle)));
            }
            else
                throw new Exception();
            result.X += center.X;
            result.Y += center.Y;
            return result;
        }
    }
}
